/*
 * Created by IntelliJ IDEA.
 * User: amrk
 * Date: 10/06/2004
 * Time: 20:57:00
 */
package com.talios.jira.browser;

import javax.swing.*;
import java.util.Hashtable;
import java.util.List;

public class FilterComboBoxModel extends DefaultComboBoxModel {
    private List filterList;

    public FilterComboBoxModel(List filterList) {
        this.filterList = filterList;
    }

    // implements javax.swing.ListModel
    public int getSize() {
        return filterList == null ? 0 : filterList.size();
    }

    // implements javax.swing.ListModel
    public Object getElementAt(int index) {
        Hashtable hash = (Hashtable) filterList.get(index);
        if (hash != null) {
            return hash.get("name");
        } else {
            return "ERR";
        }

    }

    public String getIdOfFilter(String filterName) {
        for (Object aFilterList : filterList) {
            Hashtable hashtable = (Hashtable) aFilterList;
            if (filterName.equals(hashtable.get("name"))) {
                return (String) hashtable.get("id");
            }
        }
        return null;
    }

}